import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12

Rectangle   {
    property bool autoEnd : true  //设置滚动条是否会自动到底
    property bool readOnly : false   //设置为只读
    property string textConst: ""   //edit内容
    property color border : "lightgray"

    color : border

    //带滚动条的item
    Flickable{
        id:flick
        anchors.fill: parent
        contentWidth: textInput.paintedWidth
        contentHeight: textInput.paintedHeight
        flickableDirection: Flickable.VerticalFlick
        contentY : height < textInput.paintedHeight ? contentHeight - height : 0
        clip: true
        TextEdit {
            id:textInput
            width: flick.width - bar.width
            height: paintedHeight > flick.height ? paintedHeight : flick.height
            text: textConst
            cursorVisible: true
            persistentSelection: true
            readOnly: readOnly
            wrapMode: Text.Wrap //自动换行
            selectByMouse : true
        }
        ScrollBar.vertical: ScrollBar {
            id:bar
            policy: ScrollBar.AlwaysOn
            size: parent.height / parent.contentHeight * parent.height
        }
    }
}

/*##^##
Designer {
    D{i:0;autoSize:true;height:480;width:640}
}
##^##*/
